package com.lottery.ruok.lottrey.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.common.Common;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import ui.AreaCircle;

/**
 * Created by ASUS on 2017/7/26.
 */

public class ResultsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private final String code;
    private ArrayList<String> itemListBeanArrayLists;

    public ResultsAdapter(ArrayList<String> itemListBeanArrayList,String code) {
        itemListBeanArrayLists = itemListBeanArrayList;
        this.code=code;
    }

    //创建新View，被LayoutManager所调用
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        if(viewType == 1) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.result_choose_item, viewGroup, false);
            return new ViewHolder(view);
        } else {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.result_choose_item_1, viewGroup, false);
            return new ViewHolder1(view);
        }
    }

    @Override
    public int getItemViewType(int position) {
        if(itemListBeanArrayLists.get(position).equals(",")){
            return 0;
        } else {
            return 1;
        }
    }

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        if(viewHolder instanceof ViewHolder) {
            ((ViewHolder)viewHolder).lottery_name.setText(itemListBeanArrayLists.get(position));
            Common.setBallBackground(((ViewHolder)viewHolder).lottery_name, itemListBeanArrayLists.get(position),code);
        } else {
            ((ViewHolder1)viewHolder).lottery_name.setText(itemListBeanArrayLists.get(position));
        }
    }

    //获取数据的数量
    @Override
    public int getItemCount() {
        return itemListBeanArrayLists.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.lottery_name)
        AreaCircle lottery_name;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    static class ViewHolder1 extends RecyclerView.ViewHolder{
        @BindView(R.id.lottery_name)
        TextView lottery_name;

        ViewHolder1(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}